package com.bruan.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

public class MapTest2 {
    public static void main(String[] args) {
        Map<String,Double> map = new HashMap<>();
        map.put("蜘蛛精",221.0);
        map.put("牛魔王",2221.0);
        map.put("至尊宝",2321.0);
        map.put("连楷洪",212.0);
        map.put("增运表",242.0);
        System.out.println(map);
        //遍历方式1 键找值
        Set<String> keys = map.keySet();
        for (String key : keys) {
            Double va = map.get(key);
            System.out.println(key +" ===> "+ va);
        }
        System.out.println("————————————————————————————————");
        //遍历方式2 键值对整体遍历
        Set<Map.Entry<String, Double>> entries = map.entrySet();
        for (Map.Entry<String, Double> entry : entries) {
            String key = entry.getKey();
            Double value = entry.getValue();
            System.out.println(key +"===>"+ value);
        }
        System.out.println("————————————————————————————————");
        //遍历方式3 lambda表达式
        map.forEach(new BiConsumer<String, Double>() {
            @Override
            public void accept(String k, Double v) {
                System.out.println(k+"===>"+v);
            }
        });
        //简化
        map.forEach((k,v)->{
            System.out.println(k+"===>"+v);
        });

    }
}
